import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home/index.vue'
import Detail from '@/views/detail/index.vue'
// import { getStorage } from './../utils/storage'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    component: Home
  },
  {
    path: '/detail',
    name: 'detail',
    component: Detail,
    meta: {
      hidden: true
    }
  },
  {
    path: '/kind',
    name: 'kind',
    component: () => import('@/views/kind/index.vue')
  },
  {
    path: '/cart',
    name: 'cart',
    component: () => import('@/views/cart/index.vue')
  },
  {
    path: '/user',
    name: 'user',
    component: () => import('@/views/user/index.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue'),
    meta: {
      hidden: true
    }
  },
  {
    path: '/reg_step1',
    name: 'step1',
    component: () => import('@/views/register/step1.vue'),
    meta: {
      hidden: true
    }
  },
  {
    path: '/reg_step2',
    name: 'step2',
    component: () => import('@/views/register/step2.vue'),
    meta: {
      hidden: true
    }
    // 路由独享的导航守卫 ---- 一般不推荐使用
    // beforeEnter (to, from, next) {
    //   const reg = /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/
    //   if (reg.test(getStorage('tel'))) {
    //     next()
    //   } else {
    //     // next('/reg_step1') XXXXXXX
    //     // next 默认为push
    //     next({
    //       path: '/reg_step1',
    //       replace: true
    //     })
    //   }
    // }
  },
  {
    path: '/reg_step3',
    name: 'step3',
    component: () => import('@/views/register/step3.vue'),
    meta: {
      hidden: true
    }
  },
  {
    path: '/order/:time',
    name: 'order',
    component: () => import('@/views/order/index.vue'),
    meta: {
      hidden: true
    }
  },
  {
    path: '/orderaddresslist/:time',
    name: 'orderaddresslist',
    component: () => import('@/views/order/list.vue'),
    meta: {
      hidden: true
    }
  },
  {
    path: '/orderaddressadd/:time',
    name: 'orderaddressadd',
    component: () => import('@/views/order/add.vue'),
    meta: {
      hidden: true
    }
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/search/index.vue'),
    meta: {
      hidden: true
    }
  },
  {
    path: '/searchresult',
    name: 'searchresult',
    component: () => import('@/views/search/result.vue'),
    meta: {
      hidden: true
    }
  },
  {
    path: '*',
    name: 'notFound',
    component: () => import('@/views/error/404.vue'),
    meta: { // 路由的元信息，控制底部选项卡显示
      hidden: true
    }
  }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
// 全局前置导航守卫 --- 差不多所有的路由都需要做某一些事时
// router.beforeEach((to, from, next) => {
//   console.log(to)
//   console.log(from)
//   next()
// })

export default router
